"""
读取FMEA采集卡的内容
@Time: 2021/2/5 19:50
@Author:
@File: fmea_card_scanner.py
"""
from fastapi import UploadFile
from typing import List, Tuple

import config
from models.dto.mark_dto.file_upload_dto import UploadResult
from models.normal.card_data_model import FmeaCardDataModel
from .base_scanner import CardScannerBase


from faker import Faker

fake = Faker(locale='zh_CN')

class FmeaCardScanner(CardScannerBase):
    """用来读取FMEA卡的类"""
    def __init__(self):
        super().__init__()

    async def extract_data(self, card_file: UploadFile) -> FmeaCardDataModel:
        return FmeaCardDataModel(brief=fake.sentence(),
                                 data_source_type=2,  # 数据源为 FMEA 卡
                                 code=fake.pystr(),
                                 project_func_name=fake.job(),
                                 task_stage=fake.word(),
                                 faulty_mode=fake.sentence())

    async def save(self, card_file: UploadFile,
             dir_path: str = config.upload_conf.FMEA_CARD_FILE_PATH) -> None:
        """
        保存传入的FEMA卡
        """
        await super().save(card_file, dir_path)

    async def save_and_extract_all_files(self, card_files: List[UploadFile],
                                         dir_name: str = config.upload_conf.FMEA_CARD_FILE_PATH) \
            -> Tuple[List[FmeaCardDataModel], UploadResult]:
        return await super().save_and_extract_all_files(card_files, dir_name)
